/*
 * @(#)AuthContextProviderImpl.java 2009-3-17
 * Copyright (c) 2008-2015 by CJK
 * All rights reserved.
 */
package net.beyond.core.util;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.beyond.common.auth.AuthContext;
import net.beyond.common.auth.AuthContextProvider;
import net.beyond.common.ssh.GenericService;
import net.beyond.core.entity.User;
import net.beyond.core.system.ConfigKeys;

import org.springframework.stereotype.Service;

/**
 * 
 * @author Shmiluyu
 * @version 1.000 2009-3-17
 */
@Service("util.authContextProvider")
public class AuthContextProviderImpl implements AuthContextProvider {

	@Resource
	private GenericService<User> userService;

	/*
	 * @see
	 * net.beyond.common.auth.AuthContextProvider#getAuthContext(javax.servlet
	 * .http.HttpServletRequest)
	 */
	public AuthContext getAuthContext(HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute(
				ConfigKeys.SESSION_USER_KEY);
		user = userService.get(user.getId());
		AuthContext ac = new AuthContext();
		ac.setUser(user);
		ac.setRequestURL(request.getRequestURI());
		return ac;
	}

	public GenericService<User> getUserService() {
		return userService;
	}

	public void setUserService(GenericService<User> userService) {
		this.userService = userService;
	}

}
